package com.easyedu.dean.controller;

import com.easyedu.core.entity.po.ExamPlan;
import com.easyedu.core.exception.EasyEduException;
import com.easyedu.core.util.R;
import com.easyedu.dean.service.ExamService;
import java.util.List;
import java.util.Map;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author linxi
 * 考试管理
 **/
@RestController
@RequestMapping("/dean")
public class ExamController {

     private final ExamService examService;

     public ExamController(ExamService examService) {
          this.examService = examService;
     }

     /**
      * 功能描述:获取未审批考试时间
      *
      * @return : com.easyedu.api.util.R
      **/
     @GetMapping("/grade/approval")
     public R getNeedApprovalExamTime() {
          List<ExamPlan> needApprovalExamTimeCourse = examService.getNeedApprovalExamTime();
          return R.ok().data(needApprovalExamTimeCourse);
     }

     /**
      * 功能描述:审批考试时间
      *
      * @param map 1 考试申请唯一id
      * @return : com.easyedu.api.util.R
      **/
     @PostMapping("/examTime/approval")
     public R approvalExamTime(@RequestBody Map<String, Long> map) {
          if (!map.containsKey("examPlanId")) {
               throw new EasyEduException(1999, "请输入正确参数");
          }
          Long examPlanId = map.get("examPlanId");
          examService.approvalExamTime(examPlanId);
          return R.ok().message("审批成功");
     }
}
